/*
	Copyright 2008 Marco Mustapic
	
    This file is part of Agilar GWT Widgets.

    Agilar GWT Widgets is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Agilar GWT Widgets is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Agilar GWT Widgets.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.agilar.gwt.client;

import java.util.Comparator;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

import org.agilar.gwt.colorpicker.ColorPicker;
import org.agilar.gwt.sortabletable.SortableTable;
import org.agilar.gwt.sortabletable.TableModel;

public class TestWidgets implements EntryPoint
{	
	public void onModuleLoad()
	{
		TableModel model = new TableModel(4, 2);
		
		model.setColumnAsSortable(0, new Comparator<Label>()
				{
					public int compare(Label o1, Label o2)
					{
						return o1.getText().compareTo(o2.getText());
					}
				});
		
		model.setColumnName(0, "Strings");
		model.setColumnName(1, "Ints");
		
		model.set(0, 0, new Label("pizza"));
		model.set(1, 0, new Label("cangrejo"));
		model.set(2, 0, new Label("rinoceronte"));
		model.set(3, 0, new Label("nylon"));

		model.set(0, 1, new Label("17"));
		model.set(1, 1, new Label("84"));
		model.set(2, 1, new Label("77"));
		model.set(3, 1, new Label("15"));
		
		final SortableTable table = new SortableTable();
		table.setModel(model);
		
		RootPanel.get().add(table);
		
		Button button = new Button("reduce");
		button.addClickListener(new ClickListener()
		{
			public void onClick(Widget sender)
			{
				TableModel model = new TableModel(3, 1);
				model.setColumnName(0, "char");
				model.set(0, 0, new Label("a"));
				model.set(1, 0, new Label("b"));
				model.set(2, 0, new Label("c"));
				table.setModel(model);
			}
		});

		RootPanel.get().add(button);

		button = new Button("expand");
		button.addClickListener(new ClickListener()
		{
			public void onClick(Widget sender)
			{
				TableModel model = new TableModel(4, 2);
				model.setColumnAsSortable(0, new Comparator<Label>()
						{
							public int compare(Label o1, Label o2)
							{
								return o1.getText().compareTo(o2.getText());
							}
						});
				
				model.setColumnName(0, "Strings");
				model.setColumnName(1, "Ints");
				
				model.set(0, 0, new Label("pizza"));
				model.set(1, 0, new Label("cangrejo"));
				model.set(2, 0, new Label("rinoceronte"));
				model.set(3, 0, new Label("nylon"));

				model.set(0, 1, new Label("17"));
				model.set(1, 1, new Label("84"));
				model.set(2, 1, new Label("77"));
				model.set(3, 1, new Label("15"));

				table.setModel(model);
			}
		});
		RootPanel.get().add(button);

		RootPanel.get().add(new ColorPicker());
	}

}
